let { HttpRequest, globalData, mfutil, UserAccess, addUserStat, URLChangeCommon } = getApp();
const app = getApp();


Page({
  data: {
    tilesDetail: {  // 详情数据
     
    },
    router:'pages/electron_prize/electron_prize',
  },
  onLoad(options) {
    my.hideShareMenu({
      success() {
      },
      fail() {
      },
    });
    console.log(options, "opentions---------------------------------------------");
    let { id,lucky_image ,lucky_text,prize_name,prize_sku,cta,urls} = options;
    this.setData({
      id,lucky_image,lucky_text,prize_name,prize_sku,cta:JSON.parse(cta),urls:urls    })
    console.log(urls,'222222222222222222222222222');
    this.setData({
      loadingActive:false
    })
    console.log(options, "qqqqqqqqqqqqqqqqqqqqqsss");
    this.initPage()
    /**
* 用户行为记录埋点
*/
    let routerArr = getCurrentPages();
    let params = app.globalData.params;
    let channel = app.globalData.channel;
    let UserAccessoptions = {
      grade: routerArr.length > 1 ? routerArr[routerArr.length - 2].data.router : '',
      name: routerArr[routerArr.length - 1].data.pagetitle,
      address: options.id,
    }
    let track = UserAccess(UserAccessoptions)
    // 自定义埋点
    let customAccessoptions = {
      customType: 'TileCover_' + options.id,
      // tileId: options.id
    }
    console.log(options.id, '进入奖品结束页');
    let tracks = addUserStat(customAccessoptions)
  },

  // 初始化数据
  async initPage() {
       let {  id } = this.data;
    let path = `/vans-family/api/v2.1/project/vansFamily/cms/forward/get?url=/v2/cms/api/tile/${id}`;
    let parmasObj = {
      member_id_type: 1,
      member_id: globalData.userInfo.memberId
    }
    this.setData({
      loadingActive: false
    })
    let res = await HttpRequest(path, 'POST', parmasObj, {});
     this.data.tilesDetail=res.data.data
    console.log(res,"22222222222222222222222333333333444444444");
    if (res.data.code == 0) {
      tilesDetail = res.data.data;
      let { type } = tilesDetail.tile_info;
      this.setData({
        tilesDetail,
      })
      this.setData({
        loadingActive: false
      })
    }
    this.setData({
      loadingActive: false
    })
    console.log(this.data.tilesDetail);
    
   
  },
   //pdf链接复制
  copyLink() {
    let { urls } = this.data;
    console.log(urls,"urls444444444444444444");
    my.setClipboard({
      text: urls,
      success: (res) => {
        my.showToast({
          type: 'success',
          content: '链接复制成功,请前往浏览器下载',
          duration: 1500,
        });
      }
    });
  },

    // btn 链接跳转
    urlChange(event) {
      

      let { item } = event.currentTarget.dataset;
      console.log(item);

      URLChangeCommon(item)
         /**
* 用户行为记录埋点
*/
    let routerArr = getCurrentPages();
    let params = app.globalData.params;
    let channel = app.globalData.channel;
    let UserAccessoptions = {
      grade: routerArr.length > 1 ? routerArr[routerArr.length - 2].data.router : '',
      name: routerArr[routerArr.length - 1].data.pagetitle,
      address: this.data.id,
      String4: item.cta_button_name,

    }
    let track = UserAccess(UserAccessoptions)

    // 自定义埋点
    let customAccessoptions = {
      customType: 'TileCTA_' + this.data.tilesDetail.tile_info.id + '_' + item.cta_button_name
      // tileId: this.data.tilesDetail.tile_info.id,
      // ctabtn: this.data.tilesDetail.tile_info.cta[0].cta_button_name
    }

    let tracks = addUserStat(customAccessoptions)
    },

})